<?php
function getUrlDbpediaAbstract($urldbp){
	$query = "select distinct * where {
	OPTIONAL { <".$urldbp."> rdfs:label ?l FILTER( langMatches( lang(?l), \"fr\" ) ) }.
	OPTIONAL { <".$urldbp."> dbpedia-owl:thumbnail ?t }.
	OPTIONAL { <".$urldbp."> dbpedia-owl:abstract ?a FILTER( langMatches( lang(?a), \"fr\" ) ) }.
	OPTIONAL { <".$urldbp."> dbpedia-owl:wikiPageRedirects ?r }.
	OPTIONAL { ?r rdfs:label ?lr FILTER( langMatches( lang(?lr), \"fr\" ) ) }.
	OPTIONAL { ?r dbpedia-owl:thumbnail ?tr }.
	OPTIONAL { ?r dbpedia-owl:abstract ?ar FILTER( langMatches( lang(?ar), \"fr\" ) ) }.
	}&format=application/sparql-results+json
	";
	$to = urlencode(trim($query));
	// petits problèmes d'encodage de la requête
	$find = array("%2A","%0D%0A","%28","%29","%26","%3D");
	$replace = array("*","+","(",")","&","=");
  $to1 = str_replace($find, $replace, $to);
	$searchUrl = 'http://fr.dbpedia.org/sparql?query='.$to1;
  return $searchUrl;
}
function request($url){
   // is curl installed?
   if (!function_exists('curl_init')){die('CURL is not installed!');}
   // get curl handle
   $ch= curl_init();
   // set request url
   curl_setopt($ch, CURLOPT_URL, $url);
   // return response, don't print/echo
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   /* Here you find more options for curl: http://www.php.net/curl_setopt*/
   $response = curl_exec($ch);
   curl_close($ch);
   return $response;
}

// On parse l'url
if (!empty($_GET['url'])) {
	$urlwikipedia = "<a href=\"http://fr.wikipedia.org/wiki/".$_GET['url']."\" target=\"_blank\">Voir sur WikiPédia</a>";
	$urldbpedia = 'http://fr.dbpedia.org/resource/'.$_GET['url'];
}
else $url = "Problème d'URL";
?>
<ul><li><?php echo $urlwikipedia ?></li></ul>
<?php
$jsonurlbis = getUrlDbpediaAbstract($urldbpedia);
$json = file_get_contents($jsonurlbis);
$responseArray = json_decode($json, true);
?>

<h3><?php echo $responseArray["results"]["bindings"][0]["l"]["value"] ?></h3>
<img style="width:30px;float:left;padding-right:0.5em;"
	src="<?php echo $responseArray["results"]["bindings"][0]["t"]["value"] ?>"
	title=""/>
<?php echo $responseArray["results"]["bindings"][0]["a"]["value"] ?>